/**
 * 
 */
package com.seascape.swms.system.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.seascape.swms.framework.model.Result;
import com.seascape.swms.framework.service.BaseService;
import com.seascape.swms.framework.web.BaseController;
import com.seascape.swms.system.model.Role;
import com.seascape.swms.system.service.RoleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author Lay
 *
 */
@Api("角色接口")
@RestController
@RequestMapping("/roles")
public class RoleController extends BaseController<Role>{

	@Autowired
	private RoleService roleService;

	/* (non-Javadoc)
	 * @see com.seascape.swms.framework.util.BaseController#getBaseService()
	 */
	@Override
	protected BaseService<Role> getBaseService() {
		return roleService;
	}
	
	@ApiOperation("按用户代码查询角色")
	@GetMapping("/queryRolesByUserId")
	public Result queryRolesByUserId(Integer userId) {
		return Result.success(roleService.queryRolesByUserId(userId));
	}
	
	@ApiOperation("分配人员")
	@PostMapping("/assignUsers")
	public Result assignUsers(@RequestParam("roleId") Integer roleId,@RequestParam("userIds") List<Integer> userIds) {
		roleService.assignUsers(roleId, userIds);
		return Result.success();
	}
	
	@ApiOperation("分配资源")
	@PostMapping("/assignResources")
	public Result assignResources(@RequestParam("roleId") Integer roleId,@RequestParam("resourceIds") List<Integer> resourceIds) {
		roleService.assignResources(roleId, resourceIds);
		return Result.success();
	}
}
